<template>
  <el-dialog
    title="溢价设置"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="300px">
    <el-form ref="priceForm" :model="formData" label-width="80px" >
      <el-form-item label="一级站点">
        <el-input-number v-model="formData.ONE" controls-position="right" :min="0" :precision="2"></el-input-number>
      </el-form-item>
      <el-form-item label="二级站点">
        <el-input-number v-model="formData.TWO" controls-position="right" :min="0" :precision="2"></el-input-number>
      </el-form-item>
      <el-form-item label="三级站点">
        <el-input-number v-model="formData.THREE" controls-position="right" :min="0" :precision="2"></el-input-number>
      </el-form-item>
      <el-form-item label="四级站点">
        <el-input-number v-model="formData.FOUR" controls-position="right" :min="0" :precision="2"></el-input-number>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">取 消</el-button>
      <el-button size="small" type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {movieOverflowPriceEdit} from '@/api/viewing';
import noimg from '@/assets/images/noimg.png';
import {rules} from '@/utils/validate';

export default {
  data() {
    return {
      visible: false,
      formData: {
        ONE: 0,
        TWO: 0,
        THREE: 0,
        FOUR: 0
      },
      rules: [
        rules.required
      ]
    }
  },
  methods: {
    show(price) {
      Object.assign(this.formData, {...price})
      this.visible = true;
    },
    brandItemClick(index) {
      this.selectedIndex = index;
    },
    confirm() {
      this.$refs.priceForm.validate(async(valid) => {
        if (!valid) {
          return;
        }
        try {
          let priceList = [];
          Object.keys(this.formData).forEach(key => {
            priceList.push({
              level: key,
              price: this.formData[key]
            })
          })
          const {data} = await movieOverflowPriceEdit(priceList);
          this.$emit('overflowPriceChange', this.formData.priceList);
          this.$message.success('保存成功!');
          this.visible = false;
        } catch (error) {
          
        }
      })
    }
  }
} 
</script>

<style lang="scss" scoped>
</style>